package com.dongdongshop.service.imp;

import com.alibaba.fastjson.JSONObject;
import com.dongdongshop.pojo.Comment;
import com.dongdongshop.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;


import java.util.Date;
import java.util.List;
import java.util.Queue;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public String findAll(String goodsId) {
        Query query = Query.query(Criteria.where("itemId").is(goodsId));
        List<Comment> all = mongoTemplate.find(query, Comment.class);
        String allStr = JSONObject.toJSONString(all);
        return allStr;
    }

    @Override
    public void addInfo(String content, String img, String level, String itemId, String username) {
        Comment comment = new Comment();
        comment.setContent(content);
        comment.setUserId(username);
        comment.setImg(img);
        comment.setItemId(itemId);
        comment.setLevel(level);
        comment.setCreateTime(new Date());
        mongoTemplate.save(comment);
    }
}
